package com.zcsy.manage.owner.controller.homePage;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aliyun.oss.OSSClient;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zcsy.commons.constants.Constants;
import com.zcsy.commons.constants.OwnerConstants;
import com.zcsy.commons.model.RequestJson;
import com.zcsy.manage.model.base.AppConfig;
import com.zcsy.commons.unique.UniqueNumberUtils;
import com.zcsy.commons.upload.AliyunOssUtil;
import com.zcsy.commons.upload.FileUploadUtil;
import com.zcsy.commons.upload.FileUploadUtil.UploadFileItem;
import com.zcsy.commons.util.DateUtils;
import com.zcsy.commons.util.Globals;
import com.zcsy.commons.util.PropertiesUtil;
import com.zcsy.manage.model.base.CellInfo;
import com.zcsy.manage.model.base.CommonImg;
import com.zcsy.manage.model.base.CommonToken;
import com.zcsy.manage.model.base.ShopInfo;
import com.zcsy.manage.model.complain.ComplaintsInfo;
import com.zcsy.manage.model.complain.ComplaintsReply;
import com.zcsy.manage.model.mall.AdCategory;
import com.zcsy.manage.model.mall.AdInfo;
import com.zcsy.manage.model.mall.GoodsInfo;
import com.zcsy.manage.model.news.NoticeInfo;
import com.zcsy.manage.model.system.User;
import com.zcsy.manage.owner.common.StringUtil;
import com.zcsy.manage.owner.service.common.IOCommonTokenService;
import com.zcsy.manage.service.base.IAppConfigService;
import com.zcsy.manage.service.base.ICellInfoService;
import com.zcsy.manage.service.base.ICommonImgService;
import com.zcsy.manage.service.base.IShopInfoService;
import com.zcsy.manage.service.complain.IComplaintsInfoService;
import com.zcsy.manage.service.complain.IComplaintsReplyService;
import com.zcsy.manage.service.mall.IAdCategoryService;
import com.zcsy.manage.service.mall.IAdInfoService;
import com.zcsy.manage.service.mall.IGoodsInfoService;
import com.zcsy.manage.service.news.INoticeInfoService;
import com.zcsy.manage.service.system.IUserService;

/**
 * @Title: homePageController.java
 * @Package： com.zcsy.manage.owner.controller.homePage 
 * @Description: 首页控制层
 *
 * @author caiyinli 13277030520@163.com
 * @Copyright: 2015 武汉中财数元信息技术有限公司 All rights reserved.
 * @date 2016年6月30日
 * @version 1.0
 * @see JDK1.7.0_75
 * @since
 */
@Controller
@RequestMapping(value = "homePage")
public class homePageController {
	
	@Autowired
	private IOCommonTokenService commomTokenService;
	
	@Autowired
	private INoticeInfoService noticeInfoService;
	
	@Autowired
	private IUserService userService;
	
    @Autowired
    private IComplaintsInfoService complaintsInfoService;
    
    @Autowired
    private IAppConfigService appConfigService;
    
    @Autowired
    private ICellInfoService cellInfoService;
    
    @Autowired
    private IComplaintsReplyService complaintsReplyService;

    @Autowired
    private IAdCategoryService adCategoryService;
    
    @Autowired
    private IAdInfoService adInfoService;
    
    @Autowired
    private IGoodsInfoService goodsInfoService;
    
    @Autowired
    private IShopInfoService shopInfoService;
    
    @Autowired
    private ICommonImgService commonImgService;
    
    private static PropertiesUtil propertiesUtil=new PropertiesUtil("config.properties");
    
    private static String endpoint = propertiesUtil.getProperty("OSS_ENDPOINT");
    private static String accessId= propertiesUtil.getProperty("ACCESS_ID");
    private static String accessKey= propertiesUtil.getProperty("ACCESS_KEY");
    private static String bucketName= propertiesUtil.getProperty("bucketName");
    
	/**
	 * @Description 获取首页信息：首页顶部小图标地址，未读消息条数、最新资讯动态（5条循环滚动）<br>
	 * 
	 * @param token token标识
	 * @param cellId 小区id
	 * @return 返回首页顶部小图标地址，未读消息条数、最新资讯动态（5条循环滚动）
	 * @author caiyinli 13277030520@163.com
	 * @date 2016年7月5日
	 * @see 
	 */
	@RequestMapping(value = "getHomePage")
    @ResponseBody
    public RequestJson getHomePage(String token,String cellId) {
        
        RequestJson result = new RequestJson();
        
        //调用方法传入token，无此token返回result为false
        result = commomTokenService.OrderInteractState(token , result);
        
        if (result.isSuccess()) {
            CommonToken tokenInfo = commomTokenService.selectByToken(token);
            String loginname = tokenInfo.getAccount();
            User user = userService.selectByPhone(loginname);
            
            CellInfo cellInfo = cellInfoService.selectByPrimaryKey(cellId);
            
            //未读条数查询
            int unReadCount = 0;
            if (cellInfo != null) {
            	unReadCount = noticeInfoService.selectUnreadCount(user.getId(), cellInfo.getId());
			}
            
            //查询首页小图标
            AppConfig appConfig = new AppConfig();
            appConfig.setObjType(OwnerConstants.INDEX_IMG);
            List<AppConfig> imgList = appConfigService.getAppConfigByKeyword(appConfig);
            if (CollectionUtils.isNotEmpty(imgList)) {
				for (AppConfig item : imgList) {
					item.setImgUrl(Globals.getImageUrl() + item.getImgUrl());
				}
			}
            
            //查询当前小区最新5条消息
            List<NoticeInfo> noticeInfos = noticeInfoService.getNewNoticeList(cellInfo.getId(), Constants.SHOW_FIVE);
            if(CollectionUtils.isNotEmpty(noticeInfos)){
            	for (NoticeInfo noticeInfo : noticeInfos) {
            		noticeInfo.setWapUrl(OwnerConstants.WAP_URL + "/info/cellNoticeDetail?id=" + noticeInfo.getId());
				}
            }
            
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("unReadCount", unReadCount);
            map.put("noticeInfos", noticeInfos);
            map.put("imgList", imgList);
            
            result.setResultCode(OwnerConstants.GET_USERINFO_SUCCESS);
            result.setMsg("查看成功！");
            result.setObj(map);
        } else {
            result.setResultCode(OwnerConstants.GET_USERINFO_FALSE);
            result.setMsg("网络异常！");
        }

        return result;
    }
	
	/**
	 * @Description 查询banner图<br>
	 * 
	 * @param token
	 * @param bannerType 1：获取业主首页banner图   2：获取商城banner图  3：店铺banner图（漏掉的再补充）
	 * @return 返回当前有效banner图
	 * @author caiyinli 13277030520@163.com
	 * @date 2016年7月5日
	 * @see 
	 */
	@RequestMapping(value = "getBanner")
    @ResponseBody
    public RequestJson getBanner(String token,Integer bannerType) {
        
        RequestJson result = new RequestJson();
        
        //调用方法传入token，无此token返回result为false
        result = commomTokenService.OrderInteractState(token , result);
        
        if (result.isSuccess()) {
        	AdCategory adCategory = new AdCategory();
        	List<AdInfo> adInfos = new ArrayList<AdInfo>();
        	
           if(bannerType != null){
        	   switch (bannerType) {
				case OwnerConstants.OWNER_INDEX_BANNER:
					 adCategory = adCategoryService.selectByValue("ownerindex");
					 break;
				case OwnerConstants.OWNER_GOODS_BANNER:
					 adCategory = adCategoryService.selectByValue("goodsbanner");
					 break;
				case OwnerConstants.OWNER_SHOP_BANNER:
					 adCategory = adCategoryService.selectByValue("shopbanner");
					 break;
				}
        	   
    		   if(adCategory != null){
    			   adInfos = adInfoService.selectBannerByAdCategoryId(adCategory.getId());
    			   if(CollectionUtils.isNotEmpty(adInfos)){
    				   for (AdInfo adInfo : adInfos) {
    					   adInfo.setImg(Globals.getImageUrl() + adInfo.getImg());
					}
    				   result.setResultCode(OwnerConstants.GET_USERINFO_SUCCESS);
    				   result.setMsg("数据获取成功！");
    				   result.setObj(adInfos);
    			   }else{
    				   result.setResultCode(OwnerConstants.NO_RECORD);
    				   result.setMsg("无数据！");
    				   result.setObj(adInfos);
    			   }
    		   }
           }
        } else {
            result.setResultCode(OwnerConstants.GET_USERINFO_FALSE);
            result.setMsg("网络异常！");
        }
        return result;
    }
	
	
    /**
     * @Method: getMyComplain
     * @Description 获取投诉建议列表
     * @param token
     *            标签
     * @return result
     * @author yangfan 373188993@qq.com
     * @date 2016年7月5日
     * @see
     */
    @RequestMapping(value = "getMyComplain")
    @ResponseBody
    public RequestJson getMyComplain(String token , Integer pNo) {

        RequestJson result = new RequestJson();
        
        try {
            // 指定默认为首页
            if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
                pNo = OwnerConstants.PAGE_NO;
            }
            
            // 根据token查询loginname,通过User取ownerId
            CommonToken tokenInfo = commomTokenService.selectByToken(token);
            String loginname = tokenInfo.getAccount();
            User user = userService.selectByLoginName(loginname);
            String ownerId = user.getId();
            
            // 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
            PageHelper.startPage(pNo, Constants.PAGE_SIZE);
            
            // 根据ownerId查询所需信息,返回列表对象
            List<ComplaintsInfo> complainAndAdviceList = complaintsInfoService.getComplainAndAdviceList(ownerId);
            
            if (!complainAndAdviceList.isEmpty() && (complainAndAdviceList.size() > 0)) {
                // 分页
                PageInfo<ComplaintsInfo> complainAndAdviceListP = new PageInfo<ComplaintsInfo>(complainAndAdviceList);
                result.setSuccess(true);
                result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
                result.setMsg("查询成功！");
                result.setObj(complainAndAdviceListP);
            } else {
                result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                result.setMsg("查询失败！");
            }
            
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
        
        return result;
        
    }
    
    
    /**
     * @Method: submitComplain
     * @Description 投诉建议提交接口
     * @param token          标记
     * @param photo          图片
     * @param title          标题
     * @param content        投诉建议内容
     * @param houseId        房屋Id
     * @param type           投诉类型
     * @param complainType   投诉对象 0：平台 1：商户 2：物业 3：向物业投诉
     * @param contactor      联系人
     * @param contactorPhone 联系人电话
     * @param level          危害程度
     * @param sugesstionType    1:投诉  2:建议
     * @return result
     * @author yangfan 373188993@qq.com
     * @date 2016年7月5日
     * @see
     */
    @RequestMapping(value = "submitComplain")
    @ResponseBody
    public RequestJson submitComplain(String token, String photo, String title, String content,
                                      String houseId, Integer type, Integer complainType,
                                      String contactor, String contactorPhone, Integer level,Integer sugesstionType) {

        RequestJson result = new RequestJson();
        ComplaintsInfo record = new ComplaintsInfo();
        CommonImg commonimgRecord = new CommonImg();
        
        try {
            if ((null != title) && (null != content) && (null != houseId) && (null != type)
                && (null != complainType) && (null != contactor) && (null != contactorPhone)
                && (null != level)) {
                
                String[] photoUrl = null;
                // 生成18为随机数作为id
                String id = UniqueNumberUtils.get18UniqueNumber();
                
                // 根据token查询loginname,通过User取ownerId
                CommonToken tokenInfo = commomTokenService.selectByToken(token);
                String loginname = tokenInfo.getAccount();
                User user = userService.selectByLoginName(loginname);
                String ownerId = user.getId();
                
                // 设置投诉建议插入对象属性值
                record.setId(id);
                record.setOwnerId(ownerId);
                record.setTitle(title);
                record.setContent(content);
                record.setHouseId(houseId);
                record.setType(type);
                record.setComplainType(complainType);
                record.setContactor(contactor);
                record.setContactorPhone(contactorPhone);
                record.setLevel(level);
                record.setCreateTime(DateUtils.getTimestamp());
                record.setState(OwnerConstants.COMPLAIN_STATE_NOREPELY);
                record.setSugesstionType(sugesstionType);
                
                // 返回结果：1插入成功；0插入失败
                int flag = complaintsInfoService.insert(record);
                
                if (flag == OwnerConstants.INSERT_SUCCESS) {
                    
                    if(!StringUtils.isEmpty(photo)){
                        //将得到的photo拆分
                        photoUrl = photo.split(",");
                        // 设置图片插入对象属性值
                        for (String item : photoUrl) {
                            commonimgRecord.setId(UniqueNumberUtils.get18UniqueNumber());
                            commonimgRecord.setUrl(item);
                            commonimgRecord.setName("投诉");
                            commonimgRecord.setObjType(Constants.OWNER_COMPLAINTS);
                            commonimgRecord.setObjId(id);
                            commonimgRecord.setSendTime(DateUtils.getTimestamp());
                            commonImgService.insert(commonimgRecord);
                        }
                    }
                 
                    result.setSuccess(true);
                    result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
                    result.setMsg("投诉建议提交成功！");
                } else if (flag == OwnerConstants.INSERT_FALSE) {
                    result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                    result.setMsg("投诉建议提交失败！");
                }
            }
            
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
        return result;

    }
    
    /**
     * @Method: myComplainBill
     * @Description 投诉单查询接口
     * @param token   标记
     *        infoId      投诉信息id
     * @return result
     * @author yangfan 373188993@qq.com
     * @date 2016年7月5日
     * @see
     */
    @RequestMapping(value = "myComplainBill")
    @ResponseBody
    public RequestJson myComplainBill(String token, String infoId) {

        RequestJson result = new RequestJson();
        
        try {
            // 根据id联表查询页面所需信息
            ComplaintsInfo complaintsInfo = complaintsInfoService.selectByPrimaryKey(infoId);
            List<ComplaintsReply> complaintsReplyList = complaintsReplyService.selectByInfoId(infoId);
            List<CommonImg> commonImg = commonImgService.selectImgsByObjIdAndObjType(infoId,Constants.OWNER_COMPLAINTS);
            
            if(commonImg.size() > 0){
                //遍历，将图片url加上前缀
                for (CommonImg item : commonImg) {
                    item.setUrl(Globals.getImageUrl()+item.getUrl());
                } 
            }
            
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("complaintsInfo", complaintsInfo);
            map.put("complaintsReplyList",complaintsReplyList);
            map.put("photoUrl", commonImg);
            
            
            if (complaintsInfo != null) {
                result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
                result.setSuccess(true);
                result.setMsg("查看成功！");
                result.setObj(map);
            } else {
                result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                result.setSuccess(false);
                result.setMsg("查看失败！");
            }
        } catch (Exception e) {
        	e.printStackTrace();
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
        return result;
    }
    
    /**
     * @Method: submitMyComplainReply
     * @Description 投诉内容回复提交接口
     * @param token         标记
     *        infoId        投诉信息id
     *        replyContent  投诉内容
     * @return result
     * @author yangfan 373188993@qq.com
     * @date 2016年7月5日
     * @see
     */
    @RequestMapping(value = "submitMyComplainReply")
    @ResponseBody
    public RequestJson submitMyComplainReply(String token, String infoId, String replyContent) {

        RequestJson result = new RequestJson();
        ComplaintsReply complaintsReply = new ComplaintsReply();

        try {
            if ((null != infoId) && (null != replyContent)) {
                ComplaintsInfo complaintsInfo = complaintsInfoService.selectByPrimaryKey(infoId);
                // 生成18为随机数作为id
                String id = UniqueNumberUtils.get18UniqueNumber();
                
                // 根据token查询userAccount
                CommonToken tokenInfo = commomTokenService.selectByToken(token);
                String userAccount = tokenInfo.getAccount();
                
                // 设置回复内容，类型，以及各个属性值
                complaintsReply.setId(id);
                complaintsReply.setTitle(complaintsInfo.getTitle());
                complaintsReply.setInfoId(infoId);
                complaintsReply.setReplyAccount(userAccount);
                complaintsReply.setContent(replyContent);
                complaintsReply.setReplyType(OwnerConstants.OWNER_REPLY);
                complaintsReply.setReplyTime(DateUtils.getTimestamp());
                
                // 返回结果：1插入成功；0插入失败
                int flag = complaintsReplyService.insert(complaintsReply);
                if (flag == OwnerConstants.INSERT_SUCCESS) {
                    result.setSuccess(true);
                    result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
                    result.setMsg("回复成功！");
                } else if (flag == OwnerConstants.INSERT_FALSE) {
                    result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                    result.setMsg("回复失败！");
                }
            }
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
        return result;
    }
    
	/**
	 * @Description 返回首页的秒杀商品、精品广告位、热门店铺广告位信息<br>
	 * 
	 * @return 返回首页的秒杀商品、精品广告位、热门店铺广告位信息
	 * @author caiyinli 13277030520@163.com
	 * @date 2016年7月8日
	 * @see 
	 */
	@RequestMapping(value = "getHomePageGoodsList")
    @ResponseBody
    public RequestJson getHomePageGoodsList(String cellId) {
        
        RequestJson result = new RequestJson();
        
        try {
			
				Map<String, Object> map = new HashMap<String, Object>();
				
				//秒杀专区
				List<GoodsInfo> secKillGoods = goodsInfoService.getSecKillGoodsList();
				if (CollectionUtils.isNotEmpty(secKillGoods)) {
					for (GoodsInfo goodsInfo : secKillGoods) {
						goodsInfo.setLogo(Globals.getImageUrl() + goodsInfo.getLogo());
					}
				}
				map.put("secKillGoods", secKillGoods);
				
				//精品
                AdCategory adCategory = adCategoryService.selectByValue("primeGoods");
                List<AdInfo> adInfos = new ArrayList<AdInfo>();
                if(adCategory != null){
                    adInfos = adInfoService.selectByAdCategoryId(adCategory.getId(),cellId);
                    if (CollectionUtils.isNotEmpty(adInfos)) {
                        for (AdInfo adInfo : adInfos) {
                            adInfo.setImg(Globals.getImageUrl() + adInfo.getImg());
                        }
                    }
                }
                map.put("adInfoGoods", adInfos);
                
                //热门店铺
                AdCategory hotShop = adCategoryService.selectByValue("hotShops");
                List<AdInfo> adInfoShops = new ArrayList<AdInfo>();
                if(hotShop != null){
                    adInfoShops = adInfoService.selectByAdCategoryId(hotShop.getId(),cellId);
                    if (CollectionUtils.isNotEmpty(adInfoShops)) {
                        for (AdInfo adInfoShop : adInfoShops) {
                            adInfoShop.setImg(Globals.getImageUrl() + adInfoShop.getImg());
                        }
                    }
                }
                
				map.put("adInfoShops", adInfoShops);
				result.setSuccess(true);
			    result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
			    result.setMsg("数据获取成功！");
			    result.setObj(map);
	
		} catch (Exception e) {
			 result.setSuccess(false);
			 result.setResultCode(OwnerConstants.GET_USERINFO_FALSE);
			 result.setMsg("网络异常！");
		}
        return result;
    }
	
	/**
	 * 首页精品商品更多
	 * @param cellId
	 * @param pNo
	 * @return
	 * @author: zt
	 * @date: 2016年9月2日
	 */
    @RequestMapping(value = "getHomePageJingpinGoods")
    @ResponseBody
    public RequestJson getHomePageJingpinGoods(String cellId , Integer pNo) {
        
        RequestJson result = new RequestJson();
        
        // 指定默认为首页
        if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
            pNo = OwnerConstants.PAGE_NO;
        }
        //精品
		AdCategory adCategory = adCategoryService.selectByValue("primeGoods");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("cid", adCategory.getId());
		params.put("cellId", cellId);
		
		List<GoodsInfo> adInfos = new ArrayList<GoodsInfo>();
		if(adCategory != null){
			PageHelper.startPage(pNo, Constants.PAGE_SIZE);
			adInfos = goodsInfoService.selectGoodsInfoByAdCategoryId(params);
			if (CollectionUtils.isNotEmpty(adInfos)) {
				for (GoodsInfo adInfo : adInfos) {
					adInfo.setLogo(Globals.getImageUrl() + adInfo.getLogo());
				}
			}
		}
        
        PageInfo<GoodsInfo> shopInfoP = new PageInfo<GoodsInfo>(adInfos);
        
        if(!adInfos.isEmpty()) {
            result.setSuccess(true);
            result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
            result.setMsg("获取成功！");
            result.setObj(shopInfoP);
        } else {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
            result.setMsg("无精品商品！");
        }
        
        return result;
    }
	
	/**
     * @Description 返回首页该小区全部热门店铺广告位信息<br>
     * 
     * @return 热门店铺广告位信息
     * @author yangfan 373188993@qq.com
     * @date 2016年8月29日
     * @see 
     */
    @RequestMapping(value = "getHomePageHotShop")
    @ResponseBody
    public RequestJson getHomePageHotShop(String cellId , Integer pNo) {
        
        RequestJson result = new RequestJson();
        
        // 指定默认为首页
        if (pNo == null || pNo < OwnerConstants.PAGE_NO) {
            pNo = OwnerConstants.PAGE_NO;
        }
        
        //热门店铺
        AdCategory hotShop = adCategoryService.selectByValue("hotShops");
        List<ShopInfo> shopInfo = null;
        if(hotShop != null){ 
            
            // 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
            PageHelper.startPage(pNo, Constants.PAGE_SIZE);
            shopInfo = shopInfoService.selectShopInfoByAdCategoryId(hotShop.getId(),cellId);
        }
        PageInfo<ShopInfo> shopInfoP = new PageInfo<ShopInfo>(shopInfo);
        
        if(!shopInfo.isEmpty()) {
            result.setSuccess(true);
            result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
            result.setMsg("全部热门店铺获取成功！");
            result.setObj(shopInfoP);
        } else {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
            result.setMsg("无热门店铺！");
        }
        
        return result;
    }
	
	
	/**
     * @Method: getSelfStoreId
     * @Description 获取小区自营超市店铺id
     * @param token         标记
     *        cellId        小区id
     * @return result
     * @author yangfan 373188993@qq.com
     * @date 2016年8月23日
     * @see
     */
	@RequestMapping(value = "getSelfStoreId")
    @ResponseBody
    public RequestJson getSelfStoreId(String cellId, String token) {

        RequestJson result = new RequestJson();
        try {
            List<String> selfStoreId = shopInfoService.getSelfStoreIdBycellId(cellId);
            if(!selfStoreId.isEmpty()) {
                result.setSuccess(true);
                result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
                result.setMsg("小区自营超市店铺id成功！");
                result.setObj(selfStoreId);
            } else {
                result.setSuccess(false);
                result.setResultCode(OwnerConstants.GET_USERINFO_FALSE);
                result.setMsg("未查询到相关数据！");
            }
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.GET_USERINFO_FALSE);
            result.setMsg("网络异常！");
        }
        return result;
	}
	
	/**
     * @Description 上传图片接口<br>
     * @param token
     * @return 
     * @author yangfan 373188993@qq.com
     * @date 2016年8月26日
     * @see 
     */
    @RequestMapping(value = "uploadPic", method = RequestMethod.POST)
    @ResponseBody
    public RequestJson uploadPic(String token,HttpServletRequest req) {

        RequestJson result = new RequestJson();
        ArrayList<String> photoList = new ArrayList<String>();
        StringBuffer photoUrlBuffer = new StringBuffer();
        try {
             OSSClient client = new  OSSClient(endpoint,accessId,accessKey); 
//            res.setContentType("text/html");
            final UploadFileItem[] uploadFiles = FileUploadUtil.saveUploadFile(req);

            //循环上传图片
            for (UploadFileItem uploadFileItem : uploadFiles) {
                File file = uploadFileItem.getInternalFile();
                //图片上传至阿里云服务器
                Map<String, Object> returnmap = AliyunOssUtil.uploadFile(client,bucketName, file.getName(),file); 
                String photoUrlItem = (String)returnmap.get("objectkey");
                photoList.add(photoUrlItem);
            }
            
            //将URL拼成字符串，用，隔开
            for (String item : photoList) {
                if(!"".equals(photoUrlBuffer.toString())) {
                    photoUrlBuffer.append(",");
                }
                photoUrlBuffer.append(item);
            }
            
            String photoUrl = photoUrlBuffer.toString();
            
            if(!photoList.isEmpty()){
                    result.setResultCode(OwnerConstants.RESULT_CODE_SUCCESS);
                    result.setMsg("图片上传成功！");
                    result.setObj(photoUrl);
            }else {
                result.setResultCode(OwnerConstants.RESULT_CODE_FALSE);
                result.setMsg("图片上传失败！");
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            result.setMsg("操作异常");
            result.setSuccess(false);
        }
        
        return result;
        
    }
}
